package com.opmsys.config;

import com.opmsys.interceptor.AuthInterceptor;
import com.opmsys.interceptor.LoginInterceptor;
import com.opmsys.utils.jsonWebToken.JsonWebTokenUtil;
import com.opmsys.utils.redis.RedisUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {

    final private JsonWebTokenUtil jsonWebTokenUtil;
    final private RedisUtil redisUtil;

    public SaTokenConfigure(JsonWebTokenUtil jsonWebTokenUtil, RedisUtil redisUtil) {
        this.jsonWebTokenUtil = jsonWebTokenUtil;
        this.redisUtil = redisUtil;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 登录校验
        registry.addInterceptor(new LoginInterceptor(redisUtil,jsonWebTokenUtil))
                .addPathPatterns("/**")
                .excludePathPatterns("/login","/person/password");
        //权限校验
        registry.addInterceptor(new AuthInterceptor(redisUtil,jsonWebTokenUtil))
                .addPathPatterns("/**")
                .excludePathPatterns("/login","/person/password");
    }

}